$(function(){
	$("#phone").blur(function(){
		var	phone=$("#phone").val();
			if(phone.trim()==""||phone.trim()==null){
				$("#un").html("请填写你的手机号").css('color','red');
			}else{
				$("#un").html("");
			}
	});
    $("#btn").click(function(){
    	//每次登录，相当于清空cookies
		$.cookie("uid",null)
	    var phoneVal = $("#phone").val();
	    var passwordVal = $("#password").val();
	    //每次登录，相当于清空cookies
        $.ajax({
            url :"/dologin",
            type : "post",
            dataType : "json",
            data : {
            	telephone : phoneVal,
                pwd : passwordVal,
            },
            success: function(result){
            	console.log(result.error);
            	if( result.error == "用户名或密码错误" ){
            		console.log(result.error);
            		$("#errorSpan").text(result.error);  
            	}else{
	        		console.log(result.registry.name)
	            	//存放cookie-登录ID存放到cookie
	            	$.cookie("name",result.registry.name, { expire:1  } );
	            	$.cookie("permissionsId",result.registry.permissionsId, { expire:1  } );
	            	window.location.href="index.html"
            	}
            },
            error:function(){
            	window.location.href="404.html"
            }
        });
    });
    
    $("#zhuce").click(function(){
    	window.location.href="zhuce.html"
    })
})